<?php
//PingBuWang.Com
//Copyright (c) 2017~2099 http://www.pingbuwang.com All rights reserved.

namespace app\common\exception;

use Exception;
use think\exception\Handle;

class FlybirdHandle extends Handle
{
    public function render(Exception $err)
    {

        if(request()->isAjax()){
            $code = $err->getCode()==0?500:$err->getCode();
            $msg = $code. ' : '. htmlentities($err->getMessage())."\n";

            if(config('app_debug')){
                $str = "";
                $trace = $err->getTrace();
                foreach( $trace as $kerr=>$verr){
                    $foc = $verr['file']?$verr['file']:$verr['class'] ;
                    $str.= "$kerr : ". $foc ." [line ".$verr['line']."]  ==> ".$verr['function']." \n";
                }
                $msg.= $str;

            }

            return jsonError( $msg );
        }

        //TODO::开发者对异常的操作
        //可以在此交由系统处理
        return parent::render($err);
    }

}